package registnet.base;

import java.util.List;
import java.util.Vector;

/**
 * An implementation of a course which a student has already taken;
 * Thus, a grade and a course offering is associated to the course.
 */
public class CourseTaken extends AbstractCourse{

	/**
	 * The semester when the course was taken.
	 */
	private int semesterTaken;
	
	/**
	 * The academic year when the course was taken.
	 */
	private int yearTaken;
	
	/**
	 * The grade associated with the course.
	 */
	private double grade;
	
	/**
	 * The name of the course offering associated with the course.
	 */
	private String sectionName;
	
	/**
	 * The remarks with regards to the grade associated with the course.
	 */
	private String remarks;
	
	/**
	 * The credited unit count after the course was taken.
	 */
	private int credit;
	
	/**
	 * The removal/completion grade for courses with an original grade
	 * of 4.0 or INC. associated with it.
	 */
	private double reExam;
	
	/**
	 * Default constructor which creates an "empty" <code>CourseTaken</code>.
	 */
	public CourseTaken(){
		courseCode = "";
		courseName = "";
		prerequisites = new Vector<Prerequisite>(); 
		unit = 0;
		semester = 0;
		year = 0;
		semesterTaken = 0;
		yearTaken = 0;
		grade = 0;
		sectionName = "";
		remarks = "";
		credit = 0;
		reExam = 0;
	}
	
	/**
	 * Creates a <code>CourseTaken</code> given the course code, and semester and 
	 * academic year when the course was taken.
	 * 
	 * @param courseCode
	 * @param semester
	 * @param year
	 */
	public CourseTaken(String courseCode, int semester, int year){
		this.courseCode = courseCode;
		courseName = "";
		prerequisites = new Vector<Prerequisite>(); 
		unit = 0;
		this.semester = semester;
		this.year = year;
		semesterTaken = 0;
		yearTaken = 0;
		grade = 0;
		sectionName = "";
		remarks = "";
		credit = 0;
		reExam = 0;
	}

	/**
	 * Returns the semester when the course was taken.
	 * @return the semester when the course was taken
	 */
	public int getSemesterTaken() {
		return semesterTaken;
	}

	/**
	 * Sets the semester when the course was taken. 
	 * @param semesterTaken
	 */
	public void setSemesterTaken(int semesterTaken) {
		this.semesterTaken = semesterTaken;
	}

	/**
	 * Returns the academic year when the course was taken.
	 * @return the academic year when the course was taken
	 */
	public int getYearTaken() {
		return yearTaken;
	}

	/**
	 * Sets the academic year when the course was taken.
	 * @param yearTaken
	 */
	public void setYearTaken(int yearTaken) {
		this.yearTaken = yearTaken;
	}

	/**
	 * Returns the grade associated with the course.
	 * @return the grade associated with the course.
	 */
	public double getGrade() {
		return grade;
	}

	/**
	 * Sets the grade to be associated with the course.
	 * @param grade
	 */
	public void setGrade(double grade) {
		this.grade = grade;
	}

	/**
	 * Returns the name of the course offering associated with the course.
	 * @return the name of the course offering associated with the course
	 */
	public String getSectionName() {
		return sectionName;
	}

	/**
	 * Sets  the name of the course offering associated with the course.
	 * @param sectionName
	 */
	public void setSectionName(String sectionName) {
		this.sectionName = sectionName;
	}

	/**
	 * Returns the remarks with regards to the grade associated with the course.
	 * @return the remarks with regards to the grade associated with the course
	 */
	public String getRemarks() {
		return remarks;
	}

	/**
	 * Sets the remarks with regards to the grade associated with the course.
	 * @param remarks
	 */
	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	/**
	 * Returns the credited unit count after the course was taken.
	 * @return the credited unit count after the course was taken
	 */
	public int getCredit() {
		return credit;
	}

	/**
	 * Sets  the credited unit count after the course was taken.
	 * @param credit
	 */
	public void setCredit(int credit) {
		this.credit = credit;
	}

	/**
	 * Returns the removal/completion grade.
	 * @return the removal/completion grade
	 */
	public double getReExam() {
		return reExam;
	}

	/**
	 * Sets the removal/completion grade.
	 * @param reExam
	 */
	public void setReExam(double reExam) {
		this.reExam = reExam;
	}
	
	/**
	 * Sets the list of prerequisites of the course.
	 * @param prerequisites
	 */
	public void setPrerequisites(List<Prerequisite> prerequisites){
		this.prerequisites = prerequisites;
	}
	
	/**
	 * The result is -1 if <code>course0</code> was taken before
	 * <code>course1</code> was taken. The result is positive 1 if 
	 * <code>course0</code> was taken after <code>course1</code> was
	 * taken. The result is zero if both courses was taken at the same time.
	 * 
	 * @param course0
	 * @param course1
	 * @return -1 if <code>course0</code> was taken before
	 * <code>course1</code> was taken; positive 1 if 
	 * <code>course0</code> was taken after <code>course1</code> was
	 * taken; and zero if both courses was taken at the same time.
	 */
	public static int compareByTimeTaken(CourseTaken course0, CourseTaken course1){
		int semester0 = course0.getSemesterTaken(); int semester1 = course1.getSemesterTaken();
		int year0 = course0.getYearTaken(); int year1 = course1.getYearTaken();
		if(semester0 == 3) year0--;
		if(semester1 == 3) year1--;
		
		if(year0 > year1)
			return 1;
		else if(year0 < year1)
			return -1;
		else{
			if(semester0 > semester1)
				return 1;
			else if(semester0 < semester1)
				return -1;
			else{
				return 0;
			}
		}
	}
	
	
}
